package com.yonyou.crm.sys.user.util;

import org.springside.modules.security.utils.Digests;
import org.springside.modules.utils.Encodes;

public class SecurityUtil {

	public static final int HASH_INTERATIONS = 1024;
	public static final int SALT_LENGTH = 8;

	/**
	 * 生成加密字符串
	 * @param str 要加密的字符串
	 * @param salt 加密盐
	 * @return
	 */
	public static String generateEncryptStr(String str, String salt) {

		if (str == null || str.length() == 0) {
			return "";
		}
		
		if (salt == null || salt.length() == 0) {
			return "";
		}
		
		byte[] hashPassword = Digests.sha1(str.getBytes(), Encodes.decodeHex(salt), HASH_INTERATIONS);
		return Encodes.encodeHex(hashPassword);
	}

	/**
	 * 生成加密盐
	 * @return
	 */
	public static String generateSalt() {
		return Encodes.encodeHex(Digests.generateSalt(SALT_LENGTH));
	}
}
